/*
 * Copyright (c) ShaoxiongDu <Shaoxiong.dev@aliyun.com> 2021 all Rights Reserved
 */

package zh.codegym.task.task07.task0713;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/* 
玩 Javarella
*/

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> arrint = new ArrayList<Integer>();
        ArrayList<Integer> arrint1 = new ArrayList<Integer>();
        ArrayList<Integer> arrint2 = new ArrayList<Integer>();
        ArrayList<Integer> arrint3 = new ArrayList<Integer>();

        for (int i = 0; i < 20; i++) {
            arrint.add(sc.nextInt());
        }
        for (int i = 0; i < arrint.size(); i++) {
            if (arrint.get(i) % 3 == 0) {
                arrint1.add(arrint.get(i));
            }
            if (arrint.get(i) % 2 == 0) {
                arrint2.add(arrint.get(i));
            }
            if (arrint.get(i) % 3 != 0 && arrint.get(i) % 2 != 0) {
                arrint3.add(arrint.get(i));
            }

        }
        printList(arrint1);
        printList(arrint2);
        printList(arrint3);


    }

    public static void printList(List<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
